package com.zzz.robot201.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.zzz.robot201.R;
import com.zzz.robot201.app.base.BaseViewActivity;
import com.zzz.robot201.di.component.DaggerSetComponent;
import com.zzz.robot201.mvp.contract.SetContract;
import com.zzz.robot201.mvp.presenter.SetPresenter;
import com.zzz.robot201.mvp.ui.fragment.ConnetFragment;
import com.zzz.robot201.mvp.ui.fragment.ControlFragment;
import com.zzz.robot201.mvp.ui.fragment.DataManageFragment;
import com.zzz.robot201.mvp.ui.fragment.DisplayFragment;
import com.zzz.robot201.mvp.ui.fragment.FeedBackFragment;
import com.zzz.robot201.mvp.ui.fragment.FirmwareFragment;
import com.zzz.robot201.mvp.ui.fragment.LoginOutFragment;
import com.zzz.robot201.mvp.ui.fragment.RobotFragment;
import com.zzz.robot201.mvp.ui.fragment.SystemFragment;
import com.zzz.robot201.utils.UIUtils;

import java.util.ArrayList;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import q.rorbin.verticaltablayout.VerticalTabLayout;
import q.rorbin.verticaltablayout.adapter.TabAdapter;
import q.rorbin.verticaltablayout.widget.ITabView;
import q.rorbin.verticaltablayout.widget.QTabView;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 07/05/2020 11:44
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class SetActivity extends BaseViewActivity<SetPresenter> implements SetContract.View {

    @BindView(R.id.btn_back)
    Button btnBack;
    @BindView(R.id.iv_dc)
    ImageView ivDc;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tab_set)
    VerticalTabLayout tabSet;
    @BindView(R.id.fragment_set)
    FrameLayout flySet;
    @BindView(R.id.iv_xh)
    ImageView ivXh;
    private ArrayList<String> mTitlesList;
    private ArrayList<Fragment> mFragmentsList;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerSetComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_set; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        setTitle(tvTitle, UIUtils.getString(R.string.title_set));
        ivXh.setVisibility(View.GONE);
        ivDc.setVisibility(View.GONE);
        mTitlesList = new ArrayList<>();//初始化Tab栏数据
        mTitlesList.add("机器人");
        mTitlesList.add("连接");
        mTitlesList.add("显示");
        mTitlesList.add("控制");
        mTitlesList.add("系统");
        mTitlesList.add("固件升级");
        mTitlesList.add("反馈");
        mTitlesList.add("数据管理");
        mTitlesList.add("退出");
        mFragmentsList = new ArrayList<>();//添加碎片
        mFragmentsList.add(new RobotFragment());
        mFragmentsList.add(new ConnetFragment());
        mFragmentsList.add(new DisplayFragment());
        mFragmentsList.add(new ControlFragment());
        mFragmentsList.add(new SystemFragment());
        mFragmentsList.add(new FirmwareFragment());
        mFragmentsList.add(new FeedBackFragment());
        mFragmentsList.add(new DataManageFragment());
        mFragmentsList.add(new LoginOutFragment());
        tabSet.setupWithFragment(getSupportFragmentManager(), R.id.fragment_set, mFragmentsList
                , new TabAdapter() {
                    @Override
                    public int getCount() {
                        return mTitlesList.size();
                    }

                    @Override
                    public QTabView.TabBadge getBadge(int position) {
                        return null;
                    }

                    @Override
                    public QTabView.TabIcon getIcon(int position) {
                        return null;
                    }

                    @Override
                    public QTabView.TabTitle getTitle(int position) {
                        return new QTabView.TabTitle.Builder()
                                .setContent(mTitlesList.get(position))
                                .setTextSize(9)
                                .setTextColor(0xFFFFFFFF, 0xFFFFFFFF)
                                .build();
                    }

                    @Override
                    public int getBackground(int position) {
                        return 0;
                    }
                });

    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.btn_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                killMyself();
                break;
        }
    }
}
